import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
@Injectable({
  providedIn: 'root'
})
export class SupplierService {
  data = '/Supply'
  constructor(private http: HttpClient) { }
  getSupplierClass(){
    return this.http.get(environment.apiUrl + this.data+'/GetSupplyClassWithSub' )
  }
  addSupplierClass(data:any){
    return this.http.post(environment.apiUrl + this.data+'/CreateSupplyClass', data)
  }
  editSupplierClass(id:any, data:any){
    return this.http.put(environment.apiUrl + this.data+'/UpdateSupplyClass', data, {params:{supplyClassId:id}})
  }
  deleteSupplierClass(id:any){
    return this.http.delete(environment.apiUrl + this.data + '/DeleteSupplyClass', {params:{supplyClassId:id}})
  }
  getSupplier(filter:{
    PageSize:number,
    PageNumber:number,
    SearchTerm:string,
    SupplyClassId:number,
    SearchStatus:string,
  }){
    Object.keys(filter).forEach(key => filter[key] === null ? delete filter[key] : {});
    return this.http.get(environment.apiUrl + this.data+ '/GetSupplyWithSub', {params:filter})
  }

  addSupplier(data:any){
    return this.http.post(environment.apiUrl + this.data + '/CreateSupply', data)
  }
  getSupplierById(id:any){
    return this.http.get(environment.apiUrl + this.data + '/GetSupplyById', {params:{supplyId:id}})
  }
  editSupplier(id:any, data:any){
    return this.http.put(environment.apiUrl + this.data + '/UpdateSupply', data, {params:{supplyId:id}})
  }
  enableSupplier(ids:any){
    return this.http.put(environment.apiUrl + this.data + '/EnableBatchSupply', ids)
  }
  disableSupplier(ids:any){
    return this.http.put(environment.apiUrl + this.data + '/UnEnableBatchSupply', ids)
  }
  deleteSupplier(ids:any){
    const options = {
      body: ids,
      responseType: 'text' as 'json'
    };
    return this.http.delete(environment.apiUrl + this.data + '/DeleteBatchSupply', options)
  }
  importSupplierFromExcel(file:File){
    const formData: FormData = new FormData();
    formData.append('file', file, file.name);
    return this.http.post(environment.apiUrl + '/Excel' + '/ImportSupplyFromExcel', formData, { responseType: 'blob'
    });
  }
  DownloadSupplierExcelModel(){
    return this.http.get(environment.apiUrl + '/Excel' + '/DownloadSupplyFileModel', { responseType: 'blob' });
  }
  DownloadSupplierExcelFile(){
    return this.http.get(environment.apiUrl + '/Excel' + '/DownloadSupplyFile', { responseType: 'blob' });
  }

 
}
